{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 会员系统"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 导入库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from datetime import datetime\n",
    "import time\n",
    "import uuid # 随机字符串\n",
    "\n",
    "# jupyter pandas显示设置\n",
    "# #显示所有列\n",
    "# pd.set_option('display.max_columns', None)\n",
    "# #显示所有行\n",
    "# pd.set_option('display.max_rows', None)\n",
    "# #设置value的显示长度为100，默认为50\n",
    "# pd.set_option('max_colwidth',100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 工具代码\n",
    "\n",
    "封装一些常用的函数来快速调用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 格式输出\n",
    "def print_message(*message):\n",
    "    print(\"【{}】 【{}】\".format(datetime.now(), message))\n",
    "    \n",
    "\n",
    "# 获取全部用户\n",
    "def read_user_csv():\n",
    "    users = pd.read_csv(\"user.csv\", index_col= False)\n",
    "    return users\n",
    "\n",
    "# 获取全部充值记录\n",
    "def read_deposit_csv():\n",
    "    deposits = pd.read_csv(\"deposit.csv\", index_col= False)\n",
    "    return deposits\n",
    "\n",
    "# 获取全部消费记录\n",
    "def read_cast_csv():\n",
    "    casts = pd.read_csv(\"cast.csv\", index_col= False)\n",
    "    return casts\n",
    "\n",
    "# 获取随机数据\n",
    "def get_uuid():\n",
    "    time_stamp = str(time.time())\n",
    "    namespace = uuid.NAMESPACE_URL\n",
    "    uuuid = uuid.uuid5(namespace,time_stamp)\n",
    "    uuuid_string = str(uuuid).split(\"-\")[-1]\n",
    "    # print(time_stamp_uuid)\n",
    "    return uuuid_string\n",
    "\n",
    "# 获取今日日期\n",
    "def get_today():\n",
    "    # 获取今日日期\n",
    "    now = datetime.now()\n",
    "    # print(now)\n",
    "    year = now.year\n",
    "    month = now.month\n",
    "    day = now.day\n",
    "    today = f\"{year}/{month}/{day}\"\n",
    "    # print(today)\n",
    "    return today"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 会员查询\n",
    "\n",
    "1、查询全部会员\n",
    "\n",
    "2、按名字查询会员信息\n",
    "\n",
    "3、按电话查询会员信息\n",
    "\n",
    "4、按名字/电话查询会员信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20210421</td>\n",
       "      <td>华伍锗</td>\n",
       "      <td>1996/12/15</td>\n",
       "      <td>18572609088</td>\n",
       "      <td>2021/3/23</td>\n",
       "      <td>744</td>\n",
       "      <td>1995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20210422</td>\n",
       "      <td>姜物酶</td>\n",
       "      <td>1999/1/31</td>\n",
       "      <td>15202675086</td>\n",
       "      <td>2021/8/30</td>\n",
       "      <td>3614</td>\n",
       "      <td>3433</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20210423</td>\n",
       "      <td>陶庸财</td>\n",
       "      <td>1992/9/18</td>\n",
       "      <td>18563928429</td>\n",
       "      <td>2021/10/26</td>\n",
       "      <td>3648</td>\n",
       "      <td>784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20210424</td>\n",
       "      <td>柏闪僳</td>\n",
       "      <td>1993/7/2</td>\n",
       "      <td>13954875919</td>\n",
       "      <td>2021/7/18</td>\n",
       "      <td>2864</td>\n",
       "      <td>3809</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20210425</td>\n",
       "      <td>邹萄爽</td>\n",
       "      <td>1992/1/11</td>\n",
       "      <td>15842314066</td>\n",
       "      <td>2021/5/5</td>\n",
       "      <td>93</td>\n",
       "      <td>1110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>20210497</td>\n",
       "      <td>郑幸亩</td>\n",
       "      <td>1992/11/1</td>\n",
       "      <td>16042478935</td>\n",
       "      <td>2021/10/5</td>\n",
       "      <td>1748</td>\n",
       "      <td>2661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>20210498</td>\n",
       "      <td>陶宦赛</td>\n",
       "      <td>1995/9/28</td>\n",
       "      <td>16549247662</td>\n",
       "      <td>2021/4/22</td>\n",
       "      <td>4648</td>\n",
       "      <td>1484</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>20210499</td>\n",
       "      <td>郑苇丸</td>\n",
       "      <td>1997/9/25</td>\n",
       "      <td>16197269012</td>\n",
       "      <td>2021/5/23</td>\n",
       "      <td>1694</td>\n",
       "      <td>2547</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>20210500</td>\n",
       "      <td>邹姻</td>\n",
       "      <td>1997/9/6</td>\n",
       "      <td>15561529882</td>\n",
       "      <td>2021/4/8</td>\n",
       "      <td>1320</td>\n",
       "      <td>1030</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>20210501</td>\n",
       "      <td>周花</td>\n",
       "      <td>2000/1/11</td>\n",
       "      <td>12345678901</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>0</td>\n",
       "      <td>4014</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>81 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID   姓名          生日           电话        办卡日期    积分    金额\n",
       "0   20210421  华伍锗  1996/12/15  18572609088   2021/3/23   744  1995\n",
       "1   20210422  姜物酶   1999/1/31  15202675086   2021/8/30  3614  3433\n",
       "2   20210423  陶庸财   1992/9/18  18563928429  2021/10/26  3648   784\n",
       "3   20210424  柏闪僳    1993/7/2  13954875919   2021/7/18  2864  3809\n",
       "4   20210425  邹萄爽   1992/1/11  15842314066    2021/5/5    93  1110\n",
       "..       ...  ...         ...          ...         ...   ...   ...\n",
       "76  20210497  郑幸亩   1992/11/1  16042478935   2021/10/5  1748  2661\n",
       "77  20210498  陶宦赛   1995/9/28  16549247662   2021/4/22  4648  1484\n",
       "78  20210499  郑苇丸   1997/9/25  16197269012   2021/5/23  1694  2547\n",
       "79  20210500   邹姻    1997/9/6  15561529882    2021/4/8  1320  1030\n",
       "80  20210501   周花   2000/1/11  12345678901    2022/7/6     0  4014\n",
       "\n",
       "[81 rows x 7 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 查询全部会员\n",
    "\n",
    "def read_all_users():\n",
    "    users = read_user_csv()\n",
    "    display(users)\n",
    "    \n",
    "read_all_users()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "按名字查询会员步骤：\n",
    "\n",
    "1、输入会员姓名\n",
    "\n",
    "2、如果姓名正确，会输出已为您查询到【{}】信息，否则就是输出未查询到【{}】信息，请重新输入\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入会员姓名： 周花\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【2024-05-30 06:53:09.330917】 【('已为您查询到【周花】信息',)】\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>20210501</td>\n",
       "      <td>周花</td>\n",
       "      <td>2000/1/11</td>\n",
       "      <td>12345678901</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>0</td>\n",
       "      <td>4014</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID  姓名         生日           电话      办卡日期  积分    金额\n",
       "80  20210501  周花  2000/1/11  12345678901  2022/7/6   0  4014"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 按名字查询会员信息\n",
    "def read_user_by_name():\n",
    "    users = read_user_csv()\n",
    "    user_names = users['姓名'].values.tolist()\n",
    "    while True:\n",
    "        user_name = input(\"请输入会员姓名：\")\n",
    "        if user_name in user_names:\n",
    "            user = users.loc[(users['姓名'] == user_name),:]\n",
    "            print_message(\"已为您查询到【{}】信息\".format(user_name))\n",
    "            display(user)\n",
    "            break\n",
    "        else:\n",
    "            print_message(\"未查询到【{}】信息，请重新输入\".format(user_name))\n",
    "            continue\n",
    "read_user_by_name()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "按电话查询会员步骤：\n",
    "\n",
    "1、输入会员电话\n",
    "\n",
    "2、如果电话正确，会输出已为您查询到【{}】信息，否则就是输出未查询到【{}】信息，请重新输入\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入会员电话： 16197269012\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【2022-07-06 11:21:48.100704】 【('已为您查询到【16197269012】信息',)】\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>20210499</td>\n",
       "      <td>郑苇丸</td>\n",
       "      <td>1997/9/25</td>\n",
       "      <td>16197269012</td>\n",
       "      <td>2021/5/23</td>\n",
       "      <td>1694</td>\n",
       "      <td>2547</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID   姓名         生日           电话       办卡日期    积分    金额\n",
       "78  20210499  郑苇丸  1997/9/25  16197269012  2021/5/23  1694  2547"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 按电话查询会员信息\n",
    "def read_user_by_phone():\n",
    "    users = read_user_csv()\n",
    "    user_phones = users['电话'].values.tolist()\n",
    "    while True:\n",
    "        user_phone = input(\"请输入会员电话：\")\n",
    "        if int(user_phone) in user_phones:\n",
    "            user = users.loc[(users['电话'] == int(user_phone)),:]\n",
    "            print_message(\"已为您查询到【{}】信息\".format(user_phone))\n",
    "            display(user)\n",
    "            break\n",
    "        else:\n",
    "            print_message(\"未查询到【{}】信息，请重新输入\".format(user_phone))\n",
    "            continue\n",
    "            \n",
    "read_user_by_phone()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "按名字/电话查询会员步骤：\n",
    "\n",
    "1、输入会员电话或名字\n",
    "\n",
    "2、如果电话或姓名正确，会输出该会员的信息，否则就是输出未查询到【{}】信息，请重新输入\n",
    "\n",
    "**注意：该查询和上面的不同在于，可以在名字和电话中选一个类型查询就可以查询会员信息**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入会员姓名/电话： 邹姻\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>20210500</td>\n",
       "      <td>邹姻</td>\n",
       "      <td>1997/9/6</td>\n",
       "      <td>15561529882</td>\n",
       "      <td>2021/4/8</td>\n",
       "      <td>1320</td>\n",
       "      <td>527</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID  姓名        生日           电话      办卡日期    积分   金额\n",
       "79  20210500  邹姻  1997/9/6  15561529882  2021/4/8  1320  527"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 按名字/电话查询会员信息\n",
    "def read_user():\n",
    "    users = read_user_csv()\n",
    "    user_names = users['姓名'].values.tolist()\n",
    "    user_phones = users['电话'].values.tolist()\n",
    "    while True:\n",
    "        user_input = input(\"请输入会员姓名/电话：\")\n",
    "        if user_input in user_names:\n",
    "            user = users.loc[(users['姓名'] == user_input),:]\n",
    "            display(user)\n",
    "            break\n",
    "        if int(user_input) in user_phones:\n",
    "            user = users.loc[(users['电话'] == int(user_input)),:] \n",
    "            display(user)\n",
    "            break\n",
    "        else:\n",
    "            print_message(\"未查询到【{}】信息，请重新输入\".format(user_input))\n",
    "            continue\n",
    "read_user()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 办理会员卡\n",
    "\n",
    "1、输入要添加的会员姓名，检测用户名是否存在\n",
    "\n",
    "2、若存在，然后输入该会员的电话，检测电话是否存在\n",
    "\n",
    "3、若存在，输入该会员生日，检测会员生日是否存在\n",
    "\n",
    "4、然后，输入该会员初始积分\n",
    "\n",
    "5、再输入该会员初始金额，就会输出会员添加成功了\n",
    "\n",
    "**注意：输入都不能为空**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入要添加的会员姓名： 周花\n",
      "请输入该会员电话： 12345678901\n",
      "请输入该会员生日： 2000/1/11\n",
      "请输入该会员初始积分： 0\n",
      "请输入该会员初始金额： 10\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【2022-07-06 11:23:10.716882】 【('添加会员成功',)】\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20210501</td>\n",
       "      <td>周花</td>\n",
       "      <td>2000/1/11</td>\n",
       "      <td>12345678901</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       会员ID  姓名         生日           电话      办卡日期 积分  金额\n",
       "0  20210501  周花  2000/1/11  12345678901  2022/7/6  0  10"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 办理会员卡\n",
    "def add_vip_user():\n",
    "    users = read_user_csv()\n",
    "    user_names = users['姓名'].values.tolist()\n",
    "    user_phones = users['电话'].values.tolist()\n",
    "    while True:\n",
    "        # 添加会员姓名\n",
    "        user_name_flag = True\n",
    "        while user_name_flag:\n",
    "            user_name = input(\"请输入要添加的会员姓名：\")\n",
    "            if user_name == \"\":\n",
    "                print_message(\"会员姓名输入不能为空，请重新输入！\")\n",
    "                continue\n",
    "            else:\n",
    "                user_name_flag = False\n",
    "        # 添加会员电话\n",
    "        user_phone_flag = True\n",
    "        while user_phone_flag:\n",
    "            user_phone = input(\"请输入该会员电话：\")\n",
    "            if user_phone == \"\":\n",
    "                print_message(\"会员电话输入不能为空，请重新输入！\")\n",
    "                continue\n",
    "            else:\n",
    "                user_phone_flag = False\n",
    "        # 添加会员生日\n",
    "        user_birth_flag = True\n",
    "        while user_birth_flag:\n",
    "            user_birth = input(\"请输入该会员生日：\")\n",
    "            if user_birth == \"\":\n",
    "                print_message(\"会员生日输入不能为空，请重新输入！\")\n",
    "                continue\n",
    "            else:\n",
    "                user_birth_flag = False\n",
    "        # 添加会员初始积分\n",
    "        credit_flag = True\n",
    "        while credit_flag:\n",
    "            credit = input(\"请输入该会员初始积分：\")\n",
    "            if credit == \"\":\n",
    "                print_message(\"会员初始积分输入不能为空，请重新输入！\")\n",
    "                continue\n",
    "            else:\n",
    "                credit_flag = False\n",
    "        # 添加会员初始金额\n",
    "        money_flag = True\n",
    "        while money_flag:\n",
    "            money = input(\"请输入该会员初始金额：\")\n",
    "            if money == \"\":\n",
    "                print_message(\"会员初始金额输入不能为空，请重新输入！\")\n",
    "                continue\n",
    "            else:\n",
    "                money_flag = False\n",
    "        \n",
    "        \n",
    "        last_id = users.iloc[-1].to_dict()[\"会员ID\"]\n",
    "        user_dict = {\"会员ID\":str(int(last_id)+1),\"姓名\":user_name,\"生日\":user_birth,\"电话\":user_phone,\"办卡日期\":get_today(),\"积分\":credit,\"金额\":money}\n",
    "        user_df = pd.DataFrame(user_dict,index=[0])\n",
    "        new_users = users.append(user_df, sort=False)\n",
    "        new_users.to_csv(\"user.csv\", index = False)\n",
    "        print_message(\"添加会员成功\")\n",
    "        display(user_df)\n",
    "        break\n",
    "\n",
    "add_vip_user()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 会员充值\n",
    "\n",
    "会员充值的具体步骤：\n",
    "\n",
    "1、输入代充值的会员姓名，会员存在，就进行下面步骤，否则会输出会员不存在，请重新输入\n",
    "\n",
    "2、输入充值的金额，充值金额不能为负数\n",
    "\n",
    "3、输入成功，然后会输出【{}】充值【{}】元，请确认：（y/n），输入y会员即可充值成功"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20210421</td>\n",
       "      <td>华伍锗</td>\n",
       "      <td>1996/12/15</td>\n",
       "      <td>18572609088</td>\n",
       "      <td>2021/3/23</td>\n",
       "      <td>744</td>\n",
       "      <td>1995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20210422</td>\n",
       "      <td>姜物酶</td>\n",
       "      <td>1999/1/31</td>\n",
       "      <td>15202675086</td>\n",
       "      <td>2021/8/30</td>\n",
       "      <td>3614</td>\n",
       "      <td>3433</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20210423</td>\n",
       "      <td>陶庸财</td>\n",
       "      <td>1992/9/18</td>\n",
       "      <td>18563928429</td>\n",
       "      <td>2021/10/26</td>\n",
       "      <td>3648</td>\n",
       "      <td>784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20210424</td>\n",
       "      <td>柏闪僳</td>\n",
       "      <td>1993/7/2</td>\n",
       "      <td>13954875919</td>\n",
       "      <td>2021/7/18</td>\n",
       "      <td>2864</td>\n",
       "      <td>3809</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20210425</td>\n",
       "      <td>邹萄爽</td>\n",
       "      <td>1992/1/11</td>\n",
       "      <td>15842314066</td>\n",
       "      <td>2021/5/5</td>\n",
       "      <td>93</td>\n",
       "      <td>1110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>20210497</td>\n",
       "      <td>郑幸亩</td>\n",
       "      <td>1992/11/1</td>\n",
       "      <td>16042478935</td>\n",
       "      <td>2021/10/5</td>\n",
       "      <td>1748</td>\n",
       "      <td>1661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>20210498</td>\n",
       "      <td>陶宦赛</td>\n",
       "      <td>1995/9/28</td>\n",
       "      <td>16549247662</td>\n",
       "      <td>2021/4/22</td>\n",
       "      <td>4648</td>\n",
       "      <td>1484</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>20210499</td>\n",
       "      <td>郑苇丸</td>\n",
       "      <td>1997/9/25</td>\n",
       "      <td>16197269012</td>\n",
       "      <td>2021/5/23</td>\n",
       "      <td>1694</td>\n",
       "      <td>2547</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>20210500</td>\n",
       "      <td>邹姻</td>\n",
       "      <td>1997/9/6</td>\n",
       "      <td>15561529882</td>\n",
       "      <td>2021/4/8</td>\n",
       "      <td>1320</td>\n",
       "      <td>427</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>20210501</td>\n",
       "      <td>周花</td>\n",
       "      <td>2000/1/11</td>\n",
       "      <td>12345678901</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>0</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>81 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID   姓名          生日           电话        办卡日期    积分    金额\n",
       "0   20210421  华伍锗  1996/12/15  18572609088   2021/3/23   744  1995\n",
       "1   20210422  姜物酶   1999/1/31  15202675086   2021/8/30  3614  3433\n",
       "2   20210423  陶庸财   1992/9/18  18563928429  2021/10/26  3648   784\n",
       "3   20210424  柏闪僳    1993/7/2  13954875919   2021/7/18  2864  3809\n",
       "4   20210425  邹萄爽   1992/1/11  15842314066    2021/5/5    93  1110\n",
       "..       ...  ...         ...          ...         ...   ...   ...\n",
       "76  20210497  郑幸亩   1992/11/1  16042478935   2021/10/5  1748  1661\n",
       "77  20210498  陶宦赛   1995/9/28  16549247662   2021/4/22  4648  1484\n",
       "78  20210499  郑苇丸   1997/9/25  16197269012   2021/5/23  1694  2547\n",
       "79  20210500   邹姻    1997/9/6  15561529882    2021/4/8  1320   427\n",
       "80  20210501   周花   2000/1/11  12345678901    2022/7/6     0  2010\n",
       "\n",
       "[81 rows x 7 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入待充值会员姓名 周花\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>20210501</td>\n",
       "      <td>周花</td>\n",
       "      <td>2000/1/11</td>\n",
       "      <td>12345678901</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>0</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID  姓名         生日           电话      办卡日期  积分    金额\n",
       "80  20210501  周花  2000/1/11  12345678901  2022/7/6   0  2010"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入充值金额： 1000\n",
      "【周花】充值【1000】元，请确认：（y/n） y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【2022-08-02 04:00:27.494005】 【('【周花】充值【1000】成功',)】\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>20210501</td>\n",
       "      <td>周花</td>\n",
       "      <td>2000/1/11</td>\n",
       "      <td>12345678901</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>0</td>\n",
       "      <td>3010</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID  姓名         生日           电话      办卡日期  积分    金额\n",
       "80  20210501  周花  2000/1/11  12345678901  2022/7/6   0  3010"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 会员充值-通过会员姓名充值\n",
    "def add_money_by_name():\n",
    "    users = read_user_csv()\n",
    "    display(users)\n",
    "    user_names = users['姓名'].values.tolist()\n",
    "    while True:\n",
    "        user_name = input(\"请输入待充值会员姓名\")\n",
    "        if user_name not in user_names:\n",
    "            print_message(\"会员不存在，请重新输入！\")\n",
    "            continue\n",
    "        else:\n",
    "            user = users.loc[(users['姓名'] == user_name),:]\n",
    "            display(user)\n",
    "            \n",
    "            money_flag = True\n",
    "            while money_flag:\n",
    "                money = input(\"请输入充值金额：\")\n",
    "                if int(money) < 0:\n",
    "                    print_message(\"充值金额不能为负数，请重新输入！\")\n",
    "                    continue\n",
    "                else:\n",
    "                    money_flag = False\n",
    "        \n",
    "        add_flag = True\n",
    "        while add_flag:\n",
    "            confirm = input(\"【{}】充值【{}】元，请确认：（y/n）\".format(user_name, money))\n",
    "            if confirm == \"y\":\n",
    "                # 获取”金额“index\n",
    "                user_index = list(users.columns).index('金额')\n",
    "                # 获取会员index\n",
    "                name_index = users.loc[(users['姓名'] == user_name),:].index[0]\n",
    "                # 获取会员原金额\n",
    "                user_money_dict = user.to_dict()[\"金额\"]\n",
    "                user_money_index = list(user_money_dict.keys())[0]\n",
    "                user_money = user_money_dict[user_money_index]\n",
    "                # 增加会员充值金额\n",
    "                users.iloc[name_index,user_index] = int(user_money) + int(money)\n",
    "                # 写入user表中(user.csv)\n",
    "                users.to_csv(\"user.csv\", index = False)\n",
    "                # 写入deposit表中(deposit.csv)\n",
    "                deposits = read_deposit_csv()\n",
    "                deposit_id = get_uuid()\n",
    "                user_id  = list(user.to_dict()[\"会员ID\"])[0]\n",
    "                money = money\n",
    "                day = get_today()\n",
    "                deposit_dict = {\"充值ID\":deposit_id,\"会员ID\":user_id,\"充值金额\":money,\"充值日期\":day}\n",
    "                deposit_df = pd.DataFrame(deposit_dict,index=[0])\n",
    "                new_deposits = deposits.append(deposit_df, sort=False)\n",
    "                new_deposits.to_csv(\"deposit.csv\", index = False)\n",
    "                print_message(\"【{}】充值【{}】成功\".format(user_name, money))\n",
    "                user = users.loc[(users['姓名'] == user_name),:]\n",
    "                display(user)\n",
    "                break\n",
    "            elif confirm == \"n\":\n",
    "                print_message(\"取消充值！\")\n",
    "                break\n",
    "            else:\n",
    "                print_message(\"输入错误，请重新输入！\")\n",
    "                continue\n",
    "        break\n",
    "        \n",
    "                \n",
    "add_money_by_name()           "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20210421</td>\n",
       "      <td>华伍锗</td>\n",
       "      <td>1996/12/15</td>\n",
       "      <td>18572609088</td>\n",
       "      <td>2021/3/23</td>\n",
       "      <td>744</td>\n",
       "      <td>1995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20210422</td>\n",
       "      <td>姜物酶</td>\n",
       "      <td>1999/1/31</td>\n",
       "      <td>15202675086</td>\n",
       "      <td>2021/8/30</td>\n",
       "      <td>3614</td>\n",
       "      <td>3433</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20210423</td>\n",
       "      <td>陶庸财</td>\n",
       "      <td>1992/9/18</td>\n",
       "      <td>18563928429</td>\n",
       "      <td>2021/10/26</td>\n",
       "      <td>3648</td>\n",
       "      <td>784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20210424</td>\n",
       "      <td>柏闪僳</td>\n",
       "      <td>1993/7/2</td>\n",
       "      <td>13954875919</td>\n",
       "      <td>2021/7/18</td>\n",
       "      <td>2864</td>\n",
       "      <td>3809</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20210425</td>\n",
       "      <td>邹萄爽</td>\n",
       "      <td>1992/1/11</td>\n",
       "      <td>15842314066</td>\n",
       "      <td>2021/5/5</td>\n",
       "      <td>93</td>\n",
       "      <td>1110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>20210497</td>\n",
       "      <td>郑幸亩</td>\n",
       "      <td>1992/11/1</td>\n",
       "      <td>16042478935</td>\n",
       "      <td>2021/10/5</td>\n",
       "      <td>1748</td>\n",
       "      <td>2661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>20210498</td>\n",
       "      <td>陶宦赛</td>\n",
       "      <td>1995/9/28</td>\n",
       "      <td>16549247662</td>\n",
       "      <td>2021/4/22</td>\n",
       "      <td>4648</td>\n",
       "      <td>1484</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>20210499</td>\n",
       "      <td>郑苇丸</td>\n",
       "      <td>1997/9/25</td>\n",
       "      <td>16197269012</td>\n",
       "      <td>2021/5/23</td>\n",
       "      <td>1694</td>\n",
       "      <td>2547</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>20210500</td>\n",
       "      <td>邹姻</td>\n",
       "      <td>1997/9/6</td>\n",
       "      <td>15561529882</td>\n",
       "      <td>2021/4/8</td>\n",
       "      <td>1320</td>\n",
       "      <td>928</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>20210501</td>\n",
       "      <td>周花</td>\n",
       "      <td>2000/1/11</td>\n",
       "      <td>12345678901</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>0</td>\n",
       "      <td>4010</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>81 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID   姓名          生日           电话        办卡日期    积分    金额\n",
       "0   20210421  华伍锗  1996/12/15  18572609088   2021/3/23   744  1995\n",
       "1   20210422  姜物酶   1999/1/31  15202675086   2021/8/30  3614  3433\n",
       "2   20210423  陶庸财   1992/9/18  18563928429  2021/10/26  3648   784\n",
       "3   20210424  柏闪僳    1993/7/2  13954875919   2021/7/18  2864  3809\n",
       "4   20210425  邹萄爽   1992/1/11  15842314066    2021/5/5    93  1110\n",
       "..       ...  ...         ...          ...         ...   ...   ...\n",
       "76  20210497  郑幸亩   1992/11/1  16042478935   2021/10/5  1748  2661\n",
       "77  20210498  陶宦赛   1995/9/28  16549247662   2021/4/22  4648  1484\n",
       "78  20210499  郑苇丸   1997/9/25  16197269012   2021/5/23  1694  2547\n",
       "79  20210500   邹姻    1997/9/6  15561529882    2021/4/8  1320   928\n",
       "80  20210501   周花   2000/1/11  12345678901    2022/7/6     0  4010\n",
       "\n",
       "[81 rows x 7 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入待充值会员电话 骆为\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "会员信息不存在,请重新输入!\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入待充值会员电话 15561529882\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>20210500</td>\n",
       "      <td>邹姻</td>\n",
       "      <td>1997/9/6</td>\n",
       "      <td>15561529882</td>\n",
       "      <td>2021/4/8</td>\n",
       "      <td>1320</td>\n",
       "      <td>928</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID  姓名        生日           电话      办卡日期    积分   金额\n",
       "79  20210500  邹姻  1997/9/6  15561529882  2021/4/8  1320  928"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入充值金额： 100\n",
      "【15561529882】充值【100】元，请确认：（y/n） y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【2022-08-02 06:46:36.534444】 【('【15561529882】充值【100】成功',)】\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>20210500</td>\n",
       "      <td>邹姻</td>\n",
       "      <td>1997/9/6</td>\n",
       "      <td>15561529882</td>\n",
       "      <td>2021/4/8</td>\n",
       "      <td>1320</td>\n",
       "      <td>1028</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID  姓名        生日           电话      办卡日期    积分    金额\n",
       "79  20210500  邹姻  1997/9/6  15561529882  2021/4/8  1320  1028"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 会员充值-通过会员电话充值\n",
    "def add_money_by_phone():\n",
    "    users = read_user_csv()\n",
    "    display(users)\n",
    "    user_phones = users['电话'].values.tolist()\n",
    "    while True:\n",
    "        user_phone = input(\"请输入待充值会员电话\")\n",
    "        if (str.isdigit(user_phone) is False):\n",
    "            print(\"会员信息不存在,请重新输入!\")\n",
    "            continue\n",
    "        if int(user_phone) not in user_phones:\n",
    "            print_message(\"会员不存在，请重新输入！\")\n",
    "            continue\n",
    "        else:\n",
    "            user = users.loc[(users['电话'] == int(user_phone)),:]\n",
    "            display(user)\n",
    "            \n",
    "            money_flag = True\n",
    "            while money_flag:\n",
    "                money = input(\"请输入充值金额：\")\n",
    "                if int(money) < 0:\n",
    "                    print_message(\"充值金额不能为负数，请重新输入！\")\n",
    "                    continue\n",
    "                else:\n",
    "                    money_flag = False\n",
    "        \n",
    "        add_flag = True\n",
    "        while add_flag:\n",
    "            confirm = input(\"【{}】充值【{}】元，请确认：（y/n）\".format(user_phone, money))\n",
    "            if confirm == \"y\":\n",
    "                # 获取”金额“index\n",
    "                user_index = list(users.columns).index('金额')\n",
    "                # 获取会员index\n",
    "                phone_index = users.loc[(users['电话'] == int(user_phone)),:].index[0]\n",
    "                # 获取会员原金额\n",
    "                user_money_dict = user.to_dict()[\"金额\"]\n",
    "                user_money_index = list(user_money_dict.keys())[0]\n",
    "                user_money = user_money_dict[user_money_index]\n",
    "                # 增加会员充值金额\n",
    "                users.iloc[phone_index,user_index] = int(user_money) + int(money)\n",
    "                # 写入user表中(user.csv)\n",
    "                users.to_csv(\"user.csv\", index = False)\n",
    "                # 写入deposit表中(deposit.csv)\n",
    "                deposits = read_deposit_csv()\n",
    "                deposit_id = get_uuid()\n",
    "                user_id  = list(user.to_dict()[\"会员ID\"])[0]\n",
    "                money = money\n",
    "                day = get_today()\n",
    "                deposit_dict = {\"充值ID\":deposit_id,\"会员ID\":user_id,\"充值金额\":money,\"充值日期\":day}\n",
    "                deposit_df = pd.DataFrame(deposit_dict,index=[0])\n",
    "                new_deposits = deposits.append(deposit_df, sort=False)\n",
    "                new_deposits.to_csv(\"deposit.csv\", index = False)\n",
    "                print_message(\"【{}】充值【{}】成功\".format(user_phone, money))\n",
    "                user = users.loc[(users['电话'] == int(user_phone)),:]\n",
    "                display(user)\n",
    "                break\n",
    "            elif confirm == \"n\":\n",
    "                print_message(\"取消充值！\")\n",
    "                break\n",
    "            else:\n",
    "                print_message(\"输入错误，请重新输入！\")\n",
    "                continue\n",
    "        break\n",
    "\n",
    "add_money_by_phone()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20210421</td>\n",
       "      <td>华伍锗</td>\n",
       "      <td>1996/12/15</td>\n",
       "      <td>18572609088</td>\n",
       "      <td>2021/3/23</td>\n",
       "      <td>744</td>\n",
       "      <td>1995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20210422</td>\n",
       "      <td>姜物酶</td>\n",
       "      <td>1999/1/31</td>\n",
       "      <td>15202675086</td>\n",
       "      <td>2021/8/30</td>\n",
       "      <td>3614</td>\n",
       "      <td>3433</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20210423</td>\n",
       "      <td>陶庸财</td>\n",
       "      <td>1992/9/18</td>\n",
       "      <td>18563928429</td>\n",
       "      <td>2021/10/26</td>\n",
       "      <td>3648</td>\n",
       "      <td>784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20210424</td>\n",
       "      <td>柏闪僳</td>\n",
       "      <td>1993/7/2</td>\n",
       "      <td>13954875919</td>\n",
       "      <td>2021/7/18</td>\n",
       "      <td>2864</td>\n",
       "      <td>3809</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20210425</td>\n",
       "      <td>邹萄爽</td>\n",
       "      <td>1992/1/11</td>\n",
       "      <td>15842314066</td>\n",
       "      <td>2021/5/5</td>\n",
       "      <td>93</td>\n",
       "      <td>1110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>20210497</td>\n",
       "      <td>郑幸亩</td>\n",
       "      <td>1992/11/1</td>\n",
       "      <td>16042478935</td>\n",
       "      <td>2021/10/5</td>\n",
       "      <td>1748</td>\n",
       "      <td>2661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>20210498</td>\n",
       "      <td>陶宦赛</td>\n",
       "      <td>1995/9/28</td>\n",
       "      <td>16549247662</td>\n",
       "      <td>2021/4/22</td>\n",
       "      <td>4648</td>\n",
       "      <td>1484</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>20210499</td>\n",
       "      <td>郑苇丸</td>\n",
       "      <td>1997/9/25</td>\n",
       "      <td>16197269012</td>\n",
       "      <td>2021/5/23</td>\n",
       "      <td>1694</td>\n",
       "      <td>2547</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>20210500</td>\n",
       "      <td>邹姻</td>\n",
       "      <td>1997/9/6</td>\n",
       "      <td>15561529882</td>\n",
       "      <td>2021/4/8</td>\n",
       "      <td>1320</td>\n",
       "      <td>1030</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>20210501</td>\n",
       "      <td>周花</td>\n",
       "      <td>2000/1/11</td>\n",
       "      <td>12345678901</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>0</td>\n",
       "      <td>4010</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>81 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID   姓名          生日           电话        办卡日期    积分    金额\n",
       "0   20210421  华伍锗  1996/12/15  18572609088   2021/3/23   744  1995\n",
       "1   20210422  姜物酶   1999/1/31  15202675086   2021/8/30  3614  3433\n",
       "2   20210423  陶庸财   1992/9/18  18563928429  2021/10/26  3648   784\n",
       "3   20210424  柏闪僳    1993/7/2  13954875919   2021/7/18  2864  3809\n",
       "4   20210425  邹萄爽   1992/1/11  15842314066    2021/5/5    93  1110\n",
       "..       ...  ...         ...          ...         ...   ...   ...\n",
       "76  20210497  郑幸亩   1992/11/1  16042478935   2021/10/5  1748  2661\n",
       "77  20210498  陶宦赛   1995/9/28  16549247662   2021/4/22  4648  1484\n",
       "78  20210499  郑苇丸   1997/9/25  16197269012   2021/5/23  1694  2547\n",
       "79  20210500   邹姻    1997/9/6  15561529882    2021/4/8  1320  1030\n",
       "80  20210501   周花   2000/1/11  12345678901    2022/7/6     0  4010\n",
       "\n",
       "[81 rows x 7 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入待充值会员姓名/电话:  周花\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>20210501</td>\n",
       "      <td>周花</td>\n",
       "      <td>2000/1/11</td>\n",
       "      <td>12345678901</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>0</td>\n",
       "      <td>4010</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID  姓名         生日           电话      办卡日期  积分    金额\n",
       "80  20210501  周花  2000/1/11  12345678901  2022/7/6   0  4010"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入充值金额： 4\n",
      "【周花】充值【4】元，请确认：（y/n） y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【2022-08-03 01:18:00.827297】 【('【周花】充值【4】成功',)】\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>20210501</td>\n",
       "      <td>周花</td>\n",
       "      <td>2000/1/11</td>\n",
       "      <td>12345678901</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>0</td>\n",
       "      <td>4014</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID  姓名         生日           电话      办卡日期  积分    金额\n",
       "80  20210501  周花  2000/1/11  12345678901  2022/7/6   0  4014"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 会员充值-通过会员姓名/电话充值\n",
    "def add_money():\n",
    "    users = read_user_csv()\n",
    "    display(users)\n",
    "    user_names = users['姓名'].values.tolist()\n",
    "    user_phones = users['电话'].values.tolist()\n",
    "    is_name_input = False\n",
    "    while True:\n",
    "        user_input = input(\"请输入待充值会员姓名/电话: \")\n",
    "        if user_input in user_names:\n",
    "            user = users.loc[(users['姓名'] == user_input), :]\n",
    "            display(user)\n",
    "            is_name_input = True\n",
    "            break\n",
    "\n",
    "        if (str.isdigit(user_input) is False):\n",
    "            print(\"会员信息不存在,请重新输入!\")\n",
    "            continue\n",
    "\n",
    "        if int(user_input) in user_phones:\n",
    "            user = users.loc[(users['电话'] == int(user_input)), :]\n",
    "            display(user)\n",
    "            break\n",
    "        print(\"会员信息不存在,请重新输入!\")\n",
    "        continue\n",
    "\n",
    "    money_flag = True\n",
    "    while money_flag:\n",
    "        money = input(\"请输入充值金额：\")\n",
    "        if int(money) < 0:\n",
    "            print_message(\"充值金额不能为负数，请重新输入！\")\n",
    "            continue\n",
    "        else:\n",
    "            money_flag = False\n",
    "\n",
    "    add_flag = True\n",
    "    while add_flag:\n",
    "        confirm = input(\"【{}】充值【{}】元，请确认：（y/n）\".format(user_input, money))\n",
    "        if confirm == \"y\":\n",
    "            # 获取”金额“index\n",
    "            user_index = list(users.columns).index('金额')\n",
    "            # 获取会员index\n",
    "            if is_name_input == True:\n",
    "                name_index = users.loc[(users['姓名'] == user_input), :].index[0]\n",
    "            else:\n",
    "                phone_index = users.loc[(users['电话'] == int(user_input)), :].index[0]\n",
    "            # 获取会员原金额\n",
    "            user_money_dict = user.to_dict()[\"金额\"]\n",
    "            user_money_index = list(user_money_dict.keys())[0]\n",
    "            user_money = user_money_dict[user_money_index]\n",
    "            # 增加会员充值金额\n",
    "            if is_name_input == True:\n",
    "                users.iloc[name_index, user_index] = int(user_money) + int(money)\n",
    "            else:\n",
    "                users.iloc[phone_index, user_index] = int(user_money) + int(money)\n",
    "            # 写入user表中(user.csv)\n",
    "            users.to_csv(\"user.csv\", index=False)\n",
    "            # 写入deposit表中(deposit.csv)\n",
    "            deposits = read_deposit_csv()\n",
    "            deposit_id = get_uuid()\n",
    "            user_id = list(user.to_dict()[\"会员ID\"])[0]\n",
    "            money = money\n",
    "            day = get_today()\n",
    "            deposit_dict = {\"充值ID\": deposit_id, \"会员ID\": user_id, \"充值金额\": money, \"充值日期\": day}\n",
    "            deposit_df = pd.DataFrame(deposit_dict, index=[0])\n",
    "            new_deposits = deposits.append(deposit_df, sort=False)\n",
    "            new_deposits.to_csv(\"deposit.csv\", index=False)\n",
    "            print_message(\"【{}】充值【{}】成功\".format(user_input, money))\n",
    "            user = users.loc[(users['姓名'] == user_input), :]\n",
    "            display(user)\n",
    "            break\n",
    "        elif confirm == \"n\":\n",
    "            print_message(\"取消充值！\")\n",
    "            break\n",
    "        else:\n",
    "            print_message(\"输入错误，请重新输入！\")\n",
    "            continue\n",
    "\n",
    "\n",
    "add_money()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 查看信息\n",
    "\n",
    "1、查看会员充值记录\n",
    "\n",
    "2、通过会员姓名查看某位会员充值记录\n",
    "\n",
    "3、通过会员电话查看某位会员充值记录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>充值ID</th>\n",
       "      <th>会员ID</th>\n",
       "      <th>充值金额</th>\n",
       "      <th>充值日期</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>9a6e3d55747e</td>\n",
       "      <td>79</td>\n",
       "      <td>1</td>\n",
       "      <td>2021/11/27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7582955ee7af</td>\n",
       "      <td>72</td>\n",
       "      <td>10</td>\n",
       "      <td>2021/11/27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>efef82f38e0b</td>\n",
       "      <td>68</td>\n",
       "      <td>100</td>\n",
       "      <td>2021/11/27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>f89d6f25b72a</td>\n",
       "      <td>71</td>\n",
       "      <td>1111</td>\n",
       "      <td>2021/11/27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>f0f92ae589b2</td>\n",
       "      <td>76</td>\n",
       "      <td>1000</td>\n",
       "      <td>2021/11/27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>e56a7fb3a87c</td>\n",
       "      <td>79</td>\n",
       "      <td>200</td>\n",
       "      <td>2021/11/27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>3e28bcddcfcf</td>\n",
       "      <td>80</td>\n",
       "      <td>1000</td>\n",
       "      <td>2022/7/6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>f97e62baa899</td>\n",
       "      <td>80</td>\n",
       "      <td>1000</td>\n",
       "      <td>2022/7/6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           充值ID  会员ID  充值金额        充值日期\n",
       "0  9a6e3d55747e    79     1  2021/11/27\n",
       "1  7582955ee7af    72    10  2021/11/27\n",
       "2  efef82f38e0b    68   100  2021/11/27\n",
       "3  f89d6f25b72a    71  1111  2021/11/27\n",
       "4  f0f92ae589b2    76  1000  2021/11/27\n",
       "5  e56a7fb3a87c    79   200  2021/11/27\n",
       "6  3e28bcddcfcf    80  1000    2022/7/6\n",
       "7  f97e62baa899    80  1000    2022/7/6"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 查看会员充值记录\n",
    "def read_all_deposits():\n",
    "    deposits = read_deposit_csv()\n",
    "    display(deposits)\n",
    "    \n",
    "read_all_deposits()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "通过会员姓名查看某位会员充值记录步骤：\n",
    "\n",
    "1、输入待查看会员姓名\n",
    "\n",
    "2、如果会员姓名存在，即可查询到会员的充值记录，否则会输出：该会员不存在，请重新输入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20210421</td>\n",
       "      <td>华伍锗</td>\n",
       "      <td>1996/12/15</td>\n",
       "      <td>18572609088</td>\n",
       "      <td>2021/3/23</td>\n",
       "      <td>744</td>\n",
       "      <td>1995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20210422</td>\n",
       "      <td>姜物酶</td>\n",
       "      <td>1999/1/31</td>\n",
       "      <td>15202675086</td>\n",
       "      <td>2021/8/30</td>\n",
       "      <td>3614</td>\n",
       "      <td>3433</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20210423</td>\n",
       "      <td>陶庸财</td>\n",
       "      <td>1992/9/18</td>\n",
       "      <td>18563928429</td>\n",
       "      <td>2021/10/26</td>\n",
       "      <td>3648</td>\n",
       "      <td>784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20210424</td>\n",
       "      <td>柏闪僳</td>\n",
       "      <td>1993/7/2</td>\n",
       "      <td>13954875919</td>\n",
       "      <td>2021/7/18</td>\n",
       "      <td>2864</td>\n",
       "      <td>3809</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20210425</td>\n",
       "      <td>邹萄爽</td>\n",
       "      <td>1992/1/11</td>\n",
       "      <td>15842314066</td>\n",
       "      <td>2021/5/5</td>\n",
       "      <td>93</td>\n",
       "      <td>1110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>20210497</td>\n",
       "      <td>郑幸亩</td>\n",
       "      <td>1992/11/1</td>\n",
       "      <td>16042478935</td>\n",
       "      <td>2021/10/5</td>\n",
       "      <td>1748</td>\n",
       "      <td>1661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>20210498</td>\n",
       "      <td>陶宦赛</td>\n",
       "      <td>1995/9/28</td>\n",
       "      <td>16549247662</td>\n",
       "      <td>2021/4/22</td>\n",
       "      <td>4648</td>\n",
       "      <td>1484</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>20210499</td>\n",
       "      <td>郑苇丸</td>\n",
       "      <td>1997/9/25</td>\n",
       "      <td>16197269012</td>\n",
       "      <td>2021/5/23</td>\n",
       "      <td>1694</td>\n",
       "      <td>2547</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>20210500</td>\n",
       "      <td>邹姻</td>\n",
       "      <td>1997/9/6</td>\n",
       "      <td>15561529882</td>\n",
       "      <td>2021/4/8</td>\n",
       "      <td>1320</td>\n",
       "      <td>527</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>20210501</td>\n",
       "      <td>周花</td>\n",
       "      <td>2000/1/11</td>\n",
       "      <td>12345678901</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>0</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>81 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID   姓名          生日           电话        办卡日期    积分    金额\n",
       "0   20210421  华伍锗  1996/12/15  18572609088   2021/3/23   744  1995\n",
       "1   20210422  姜物酶   1999/1/31  15202675086   2021/8/30  3614  3433\n",
       "2   20210423  陶庸财   1992/9/18  18563928429  2021/10/26  3648   784\n",
       "3   20210424  柏闪僳    1993/7/2  13954875919   2021/7/18  2864  3809\n",
       "4   20210425  邹萄爽   1992/1/11  15842314066    2021/5/5    93  1110\n",
       "..       ...  ...         ...          ...         ...   ...   ...\n",
       "76  20210497  郑幸亩   1992/11/1  16042478935   2021/10/5  1748  1661\n",
       "77  20210498  陶宦赛   1995/9/28  16549247662   2021/4/22  4648  1484\n",
       "78  20210499  郑苇丸   1997/9/25  16197269012   2021/5/23  1694  2547\n",
       "79  20210500   邹姻    1997/9/6  15561529882    2021/4/8  1320   527\n",
       "80  20210501   周花   2000/1/11  12345678901    2022/7/6     0  2010\n",
       "\n",
       "[81 rows x 7 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入待查看会员姓名： 周花\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>20210501</td>\n",
       "      <td>周花</td>\n",
       "      <td>2000/1/11</td>\n",
       "      <td>12345678901</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>0</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID  姓名         生日           电话      办卡日期  积分    金额\n",
       "80  20210501  周花  2000/1/11  12345678901  2022/7/6   0  2010"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【2022-07-06 11:25:54.925969】 【('会员【周花】充值记录查询成功:',)】\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>充值ID</th>\n",
       "      <th>会员ID</th>\n",
       "      <th>充值金额</th>\n",
       "      <th>充值日期</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>3e28bcddcfcf</td>\n",
       "      <td>80</td>\n",
       "      <td>1000</td>\n",
       "      <td>2022/7/6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>f97e62baa899</td>\n",
       "      <td>80</td>\n",
       "      <td>1000</td>\n",
       "      <td>2022/7/6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           充值ID  会员ID  充值金额      充值日期\n",
       "6  3e28bcddcfcf    80  1000  2022/7/6\n",
       "7  f97e62baa899    80  1000  2022/7/6"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 通过会员姓名查看某位会员充值记录\n",
    "\n",
    "def read_someone_deposit_by_name():\n",
    "    deposits = read_deposit_csv()\n",
    "    \n",
    "    users = read_user_csv()\n",
    "    user_names = users['姓名'].values.tolist()\n",
    "    display(users)\n",
    "    \n",
    "    while True:\n",
    "        user_name = input(\"请输入待查看会员姓名：\")\n",
    "        if user_name not in user_names:\n",
    "            print_message(\"该会员不存在，请重新输入！\")\n",
    "            continue\n",
    "        else:\n",
    "            user = users.loc[(users['姓名'] == user_name),:]\n",
    "            display(user)\n",
    "            user_id  = list(user.to_dict()[\"会员ID\"])[0]\n",
    "            user_deposit = deposits.loc[(deposits['会员ID'] == user_id),:]\n",
    "            print_message(\"会员【{}】充值记录查询成功:\".format(user_name))\n",
    "            display(user_deposit)\n",
    "            break\n",
    "            \n",
    "read_someone_deposit_by_name()  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "通过会员电话查看某位会员充值记录步骤：\n",
    "\n",
    "1、输入待查看会员电话\n",
    "\n",
    "2、如果电话存在，即可查询到会员的充值记录，否则会输出：该会员不存在，请重新输入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20210421</td>\n",
       "      <td>华伍锗</td>\n",
       "      <td>1996/12/15</td>\n",
       "      <td>18572609088</td>\n",
       "      <td>2021/3/23</td>\n",
       "      <td>744</td>\n",
       "      <td>1995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20210422</td>\n",
       "      <td>姜物酶</td>\n",
       "      <td>1999/1/31</td>\n",
       "      <td>15202675086</td>\n",
       "      <td>2021/8/30</td>\n",
       "      <td>3614</td>\n",
       "      <td>3433</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20210423</td>\n",
       "      <td>陶庸财</td>\n",
       "      <td>1992/9/18</td>\n",
       "      <td>18563928429</td>\n",
       "      <td>2021/10/26</td>\n",
       "      <td>3648</td>\n",
       "      <td>784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20210424</td>\n",
       "      <td>柏闪僳</td>\n",
       "      <td>1993/7/2</td>\n",
       "      <td>13954875919</td>\n",
       "      <td>2021/7/18</td>\n",
       "      <td>2864</td>\n",
       "      <td>3809</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20210425</td>\n",
       "      <td>邹萄爽</td>\n",
       "      <td>1992/1/11</td>\n",
       "      <td>15842314066</td>\n",
       "      <td>2021/5/5</td>\n",
       "      <td>93</td>\n",
       "      <td>1110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>20210497</td>\n",
       "      <td>郑幸亩</td>\n",
       "      <td>1992/11/1</td>\n",
       "      <td>16042478935</td>\n",
       "      <td>2021/10/5</td>\n",
       "      <td>1748</td>\n",
       "      <td>1661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>20210498</td>\n",
       "      <td>陶宦赛</td>\n",
       "      <td>1995/9/28</td>\n",
       "      <td>16549247662</td>\n",
       "      <td>2021/4/22</td>\n",
       "      <td>4648</td>\n",
       "      <td>1484</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>20210499</td>\n",
       "      <td>郑苇丸</td>\n",
       "      <td>1997/9/25</td>\n",
       "      <td>16197269012</td>\n",
       "      <td>2021/5/23</td>\n",
       "      <td>1694</td>\n",
       "      <td>2547</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>20210500</td>\n",
       "      <td>邹姻</td>\n",
       "      <td>1997/9/6</td>\n",
       "      <td>15561529882</td>\n",
       "      <td>2021/4/8</td>\n",
       "      <td>1320</td>\n",
       "      <td>527</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>20210501</td>\n",
       "      <td>周花</td>\n",
       "      <td>2000/1/11</td>\n",
       "      <td>12345678901</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>0</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>81 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID   姓名          生日           电话        办卡日期    积分    金额\n",
       "0   20210421  华伍锗  1996/12/15  18572609088   2021/3/23   744  1995\n",
       "1   20210422  姜物酶   1999/1/31  15202675086   2021/8/30  3614  3433\n",
       "2   20210423  陶庸财   1992/9/18  18563928429  2021/10/26  3648   784\n",
       "3   20210424  柏闪僳    1993/7/2  13954875919   2021/7/18  2864  3809\n",
       "4   20210425  邹萄爽   1992/1/11  15842314066    2021/5/5    93  1110\n",
       "..       ...  ...         ...          ...         ...   ...   ...\n",
       "76  20210497  郑幸亩   1992/11/1  16042478935   2021/10/5  1748  1661\n",
       "77  20210498  陶宦赛   1995/9/28  16549247662   2021/4/22  4648  1484\n",
       "78  20210499  郑苇丸   1997/9/25  16197269012   2021/5/23  1694  2547\n",
       "79  20210500   邹姻    1997/9/6  15561529882    2021/4/8  1320   527\n",
       "80  20210501   周花   2000/1/11  12345678901    2022/7/6     0  2010\n",
       "\n",
       "[81 rows x 7 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入待查看会员电话： 12345678901\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>20210501</td>\n",
       "      <td>周花</td>\n",
       "      <td>2000/1/11</td>\n",
       "      <td>12345678901</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>0</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID  姓名         生日           电话      办卡日期  积分    金额\n",
       "80  20210501  周花  2000/1/11  12345678901  2022/7/6   0  2010"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【2022-07-06 11:26:06.170530】 【('会员【12345678901】充值记录查询成功:',)】\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>充值ID</th>\n",
       "      <th>会员ID</th>\n",
       "      <th>充值金额</th>\n",
       "      <th>充值日期</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>3e28bcddcfcf</td>\n",
       "      <td>80</td>\n",
       "      <td>1000</td>\n",
       "      <td>2022/7/6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>f97e62baa899</td>\n",
       "      <td>80</td>\n",
       "      <td>1000</td>\n",
       "      <td>2022/7/6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           充值ID  会员ID  充值金额      充值日期\n",
       "6  3e28bcddcfcf    80  1000  2022/7/6\n",
       "7  f97e62baa899    80  1000  2022/7/6"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 通过会员电话查看某位会员充值记录\n",
    "def read_someone_deposit_by_phone():\n",
    "    deposits = read_deposit_csv()\n",
    "    \n",
    "    users = read_user_csv()\n",
    "    user_phones = users['电话'].values.tolist()\n",
    "    display(users)\n",
    "    \n",
    "    while True:\n",
    "        user_phone = input(\"请输入待查看会员电话：\")\n",
    "        if int(user_phone) not in user_phones:\n",
    "            print_message(\"该会员不存在，请重新输入！\")\n",
    "            continue\n",
    "        else:\n",
    "            user = users.loc[(users['电话'] == int(user_phone)),:]\n",
    "            display(user)\n",
    "            user_id  = list(user.to_dict()[\"会员ID\"])[0]\n",
    "            user_deposit = deposits.loc[(deposits['会员ID'] == user_id),:]\n",
    "            print_message(\"会员【{}】充值记录查询成功:\".format(user_phone))\n",
    "            display(user_deposit)\n",
    "            break\n",
    "            \n",
    "read_someone_deposit_by_phone()  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 消费记录\n",
    "\n",
    "会员消费记录步骤：\n",
    "\n",
    "1、输入会员的姓名\n",
    "\n",
    "2、如果存在，则继续输入会员电话，否则请重新输入姓名\n",
    "\n",
    "3、电话正确，则输入消费的内容，否则继续输入正确的电话号码（消费内容不能为空）\n",
    "\n",
    "4、然后再继续输入消费的金额（金额不能为空）\n",
    "\n",
    "5、然后确认会员消费信息，确认无误后输入y，即可生成会员消费记录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【2022-07-06 11:26:13.309425】 【('会员消费系统，欢迎您！',)】\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20210421</td>\n",
       "      <td>华伍锗</td>\n",
       "      <td>1996/12/15</td>\n",
       "      <td>18572609088</td>\n",
       "      <td>2021/3/23</td>\n",
       "      <td>744</td>\n",
       "      <td>1995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20210422</td>\n",
       "      <td>姜物酶</td>\n",
       "      <td>1999/1/31</td>\n",
       "      <td>15202675086</td>\n",
       "      <td>2021/8/30</td>\n",
       "      <td>3614</td>\n",
       "      <td>3433</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20210423</td>\n",
       "      <td>陶庸财</td>\n",
       "      <td>1992/9/18</td>\n",
       "      <td>18563928429</td>\n",
       "      <td>2021/10/26</td>\n",
       "      <td>3648</td>\n",
       "      <td>784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20210424</td>\n",
       "      <td>柏闪僳</td>\n",
       "      <td>1993/7/2</td>\n",
       "      <td>13954875919</td>\n",
       "      <td>2021/7/18</td>\n",
       "      <td>2864</td>\n",
       "      <td>3809</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20210425</td>\n",
       "      <td>邹萄爽</td>\n",
       "      <td>1992/1/11</td>\n",
       "      <td>15842314066</td>\n",
       "      <td>2021/5/5</td>\n",
       "      <td>93</td>\n",
       "      <td>1110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>20210497</td>\n",
       "      <td>郑幸亩</td>\n",
       "      <td>1992/11/1</td>\n",
       "      <td>16042478935</td>\n",
       "      <td>2021/10/5</td>\n",
       "      <td>1748</td>\n",
       "      <td>1661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>20210498</td>\n",
       "      <td>陶宦赛</td>\n",
       "      <td>1995/9/28</td>\n",
       "      <td>16549247662</td>\n",
       "      <td>2021/4/22</td>\n",
       "      <td>4648</td>\n",
       "      <td>1484</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>20210499</td>\n",
       "      <td>郑苇丸</td>\n",
       "      <td>1997/9/25</td>\n",
       "      <td>16197269012</td>\n",
       "      <td>2021/5/23</td>\n",
       "      <td>1694</td>\n",
       "      <td>2547</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>20210500</td>\n",
       "      <td>邹姻</td>\n",
       "      <td>1997/9/6</td>\n",
       "      <td>15561529882</td>\n",
       "      <td>2021/4/8</td>\n",
       "      <td>1320</td>\n",
       "      <td>527</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>20210501</td>\n",
       "      <td>周花</td>\n",
       "      <td>2000/1/11</td>\n",
       "      <td>12345678901</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>0</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>81 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID   姓名          生日           电话        办卡日期    积分    金额\n",
       "0   20210421  华伍锗  1996/12/15  18572609088   2021/3/23   744  1995\n",
       "1   20210422  姜物酶   1999/1/31  15202675086   2021/8/30  3614  3433\n",
       "2   20210423  陶庸财   1992/9/18  18563928429  2021/10/26  3648   784\n",
       "3   20210424  柏闪僳    1993/7/2  13954875919   2021/7/18  2864  3809\n",
       "4   20210425  邹萄爽   1992/1/11  15842314066    2021/5/5    93  1110\n",
       "..       ...  ...         ...          ...         ...   ...   ...\n",
       "76  20210497  郑幸亩   1992/11/1  16042478935   2021/10/5  1748  1661\n",
       "77  20210498  陶宦赛   1995/9/28  16549247662   2021/4/22  4648  1484\n",
       "78  20210499  郑苇丸   1997/9/25  16197269012   2021/5/23  1694  2547\n",
       "79  20210500   邹姻    1997/9/6  15561529882    2021/4/8  1320   527\n",
       "80  20210501   周花   2000/1/11  12345678901    2022/7/6     0  2010\n",
       "\n",
       "[81 rows x 7 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "请输入会员姓名： 邹姻\n",
      "请输入会员电话： 15561529882\n",
      "请输入消费内容： 按摩\n",
      "请输入消费金额： 100\n",
      "会员【邹姻】消费【按摩】，金额【100】元，请确认：（y/n） y\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "【2022-07-06 11:27:14.747042】 【('会员【邹姻】消费【按摩】，金额【100】元',)】\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>消费ID</th>\n",
       "      <th>会员ID</th>\n",
       "      <th>消费金额</th>\n",
       "      <th>消费日期</th>\n",
       "      <th>消费内容</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>f12243f571e9</td>\n",
       "      <td>79</td>\n",
       "      <td>100</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>按摩</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           消费ID  会员ID 消费金额      消费日期 消费内容\n",
       "0  f12243f571e9    79  100  2022/7/6   按摩"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>20210500</td>\n",
       "      <td>邹姻</td>\n",
       "      <td>1997/9/6</td>\n",
       "      <td>15561529882</td>\n",
       "      <td>2021/4/8</td>\n",
       "      <td>1320</td>\n",
       "      <td>427</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID  姓名        生日           电话      办卡日期    积分   金额\n",
       "79  20210500  邹姻  1997/9/6  15561529882  2021/4/8  1320  427"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 会员消费\n",
    "\n",
    "def cast_something():\n",
    "    print_message(\"会员消费系统，欢迎您！\")\n",
    "    users = read_user_csv()\n",
    "    display(users)\n",
    "    user_names = users['姓名'].values.tolist()\n",
    "    user_phones = users['电话'].values.tolist()\n",
    "    \n",
    "    while True:\n",
    "        user_name = input(\"请输入会员姓名：\")\n",
    "        if user_name not in user_names:\n",
    "            print_message(\"会员不存在，请重新输入！\")\n",
    "            continue\n",
    "        else:\n",
    "            user = users.loc[(users['姓名'] == user_name),:]\n",
    "            # 获取该用户电话\n",
    "            user_phone_dict = user.to_dict()[\"电话\"]\n",
    "            user_phone_index = list(user_phone_dict.keys())[0]\n",
    "            user_phone_gt = user_phone_dict[user_phone_index]\n",
    "            user_phone = input(\"请输入会员电话：\")\n",
    "            if user_phone == \"\" or int(user_phone) != int(user_phone_gt):\n",
    "                print_message(\"会员电话不正确，请重新输入！\")\n",
    "                continue\n",
    "            else:\n",
    "                # 添加会员消费内容\n",
    "                thing_flag = True\n",
    "                while thing_flag:\n",
    "                    thing = input(\"请输入消费内容：\")\n",
    "                    if thing == \"\":\n",
    "                        print_message(\"会员消费内容不能为空，请重新输入！\")\n",
    "                        continue\n",
    "                    else:\n",
    "                        thing_flag = False\n",
    "\n",
    "                # 添加会员消费金额\n",
    "                money_flag = True\n",
    "                while money_flag:\n",
    "                    money = input(\"请输入消费金额：\")\n",
    "                    if money == \"\":\n",
    "                        print_message(\"会员消费金额不能为空，请重新输入！\")\n",
    "                        continue\n",
    "                    else:\n",
    "                        money_flag = False\n",
    "\n",
    "                # 确认是否消费\n",
    "                add_flag = True\n",
    "                while add_flag:\n",
    "                    confirm = input(\"会员【{}】消费【{}】，金额【{}】元，请确认：（y/n）\".format(user_name, thing, money))\n",
    "                    if confirm == \"y\":\n",
    "                        # 修改user表（user.csv）\n",
    "                        # 获取”金额“index\n",
    "                        user_index = list(users.columns).index('金额')\n",
    "                        # 获取会员index\n",
    "                        name_index = users.loc[(users['姓名'] == user_name),:].index[0]\n",
    "                        # 获取会员原金额\n",
    "                        user_money_dict = user.to_dict()[\"金额\"]\n",
    "                        user_money_index = list(user_money_dict.keys())[0]\n",
    "                        user_money = user_money_dict[user_money_index]\n",
    "                        # 减去会员原始金额\n",
    "                        rest_money = int(user_money) - int(money)\n",
    "                        if rest_money < 0:\n",
    "                            print_message(\"余额不足，无法购买，请重新选择商品\")\n",
    "                            break\n",
    "                        users.iloc[name_index,user_index] = rest_money\n",
    "                        users.to_csv(\"user.csv\", index = False)\n",
    "                        # 写入cast表中(cast.csv)\n",
    "                        casts = read_cast_csv()\n",
    "                        cast_id = get_uuid()\n",
    "                        user_id  = list(user.to_dict()[\"会员ID\"])[0]\n",
    "                        day = get_today()\n",
    "                        cast_dict = {\"消费ID\":cast_id,\"会员ID\":user_id,\"消费金额\":money,\"消费日期\":day, \"消费内容\":thing}\n",
    "                        cast_df = pd.DataFrame(cast_dict,index=[0])\n",
    "                        new_casts = casts.append(cast_df, sort=False)\n",
    "                        new_casts.to_csv(\"cast.csv\", index = False)\n",
    "                        print_message(\"会员【{}】消费【{}】，金额【{}】元\".format(user_name, thing, money))\n",
    "                        display(cast_df)\n",
    "                        \n",
    "                        user = users.loc[(users['电话'] == int(user_phone)),:]\n",
    "                        display(user)\n",
    "                        break\n",
    "                    elif confirm == \"n\":\n",
    "                        print_message(\"取消充值！\")\n",
    "                        break\n",
    "                    else:\n",
    "                        print_message(\"输入错误，请重新输入！\")\n",
    "                        continue\n",
    "            break\n",
    "                \n",
    "cast_something()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>消费ID</th>\n",
       "      <th>会员ID</th>\n",
       "      <th>消费内容</th>\n",
       "      <th>消费金额</th>\n",
       "      <th>消费日期</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>b32590c08225</td>\n",
       "      <td>79</td>\n",
       "      <td>LV包包</td>\n",
       "      <td>3000</td>\n",
       "      <td>2021/11/28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>e4956cc0281d</td>\n",
       "      <td>73</td>\n",
       "      <td>任天堂switch</td>\n",
       "      <td>2000</td>\n",
       "      <td>2021/11/28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>7d3b8699cf40</td>\n",
       "      <td>79</td>\n",
       "      <td>包包</td>\n",
       "      <td>2000</td>\n",
       "      <td>2021/11/28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>f12243f571e9</td>\n",
       "      <td>79</td>\n",
       "      <td>按摩</td>\n",
       "      <td>100</td>\n",
       "      <td>2022/7/6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           消费ID  会员ID       消费内容  消费金额        消费日期\n",
       "0  b32590c08225    79       LV包包  3000  2021/11/28\n",
       "1  e4956cc0281d    73  任天堂switch  2000  2021/11/28\n",
       "2  7d3b8699cf40    79         包包  2000  2021/11/28\n",
       "3  f12243f571e9    79         按摩   100    2022/7/6"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 查看全部会员消费\n",
    "\n",
    "def read_all_casts():\n",
    "    casts = read_cast_csv()\n",
    "    display(casts)\n",
    "\n",
    "read_all_casts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "查看某位会员消费记录步骤：\n",
    "\n",
    "1、输入会员姓名\n",
    "\n",
    "2、如果会员姓名正确即可查询到该会员的消费记录，否则，继续输入正确的会员姓名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>会员ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>生日</th>\n",
       "      <th>电话</th>\n",
       "      <th>办卡日期</th>\n",
       "      <th>积分</th>\n",
       "      <th>金额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20210421</td>\n",
       "      <td>华伍锗</td>\n",
       "      <td>1996/12/15</td>\n",
       "      <td>18572609088</td>\n",
       "      <td>2021/3/23</td>\n",
       "      <td>744</td>\n",
       "      <td>1995</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20210422</td>\n",
       "      <td>姜物酶</td>\n",
       "      <td>1999/1/31</td>\n",
       "      <td>15202675086</td>\n",
       "      <td>2021/8/30</td>\n",
       "      <td>3614</td>\n",
       "      <td>3433</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20210423</td>\n",
       "      <td>陶庸财</td>\n",
       "      <td>1992/9/18</td>\n",
       "      <td>18563928429</td>\n",
       "      <td>2021/10/26</td>\n",
       "      <td>3648</td>\n",
       "      <td>784</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20210424</td>\n",
       "      <td>柏闪僳</td>\n",
       "      <td>1993/7/2</td>\n",
       "      <td>13954875919</td>\n",
       "      <td>2021/7/18</td>\n",
       "      <td>2864</td>\n",
       "      <td>3809</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20210425</td>\n",
       "      <td>邹萄爽</td>\n",
       "      <td>1992/1/11</td>\n",
       "      <td>15842314066</td>\n",
       "      <td>2021/5/5</td>\n",
       "      <td>93</td>\n",
       "      <td>1110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>20210497</td>\n",
       "      <td>郑幸亩</td>\n",
       "      <td>1992/11/1</td>\n",
       "      <td>16042478935</td>\n",
       "      <td>2021/10/5</td>\n",
       "      <td>1748</td>\n",
       "      <td>2661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>20210498</td>\n",
       "      <td>陶宦赛</td>\n",
       "      <td>1995/9/28</td>\n",
       "      <td>16549247662</td>\n",
       "      <td>2021/4/22</td>\n",
       "      <td>4648</td>\n",
       "      <td>1484</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>20210499</td>\n",
       "      <td>郑苇丸</td>\n",
       "      <td>1997/9/25</td>\n",
       "      <td>16197269012</td>\n",
       "      <td>2021/5/23</td>\n",
       "      <td>1694</td>\n",
       "      <td>2547</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>20210500</td>\n",
       "      <td>邹姻</td>\n",
       "      <td>1997/9/6</td>\n",
       "      <td>15561529882</td>\n",
       "      <td>2021/4/8</td>\n",
       "      <td>1320</td>\n",
       "      <td>1030</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>20210501</td>\n",
       "      <td>周花</td>\n",
       "      <td>2000/1/11</td>\n",
       "      <td>12345678901</td>\n",
       "      <td>2022/7/6</td>\n",
       "      <td>0</td>\n",
       "      <td>4014</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>81 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        会员ID   姓名          生日           电话        办卡日期    积分    金额\n",
       "0   20210421  华伍锗  1996/12/15  18572609088   2021/3/23   744  1995\n",
       "1   20210422  姜物酶   1999/1/31  15202675086   2021/8/30  3614  3433\n",
       "2   20210423  陶庸财   1992/9/18  18563928429  2021/10/26  3648   784\n",
       "3   20210424  柏闪僳    1993/7/2  13954875919   2021/7/18  2864  3809\n",
       "4   20210425  邹萄爽   1992/1/11  15842314066    2021/5/5    93  1110\n",
       "..       ...  ...         ...          ...         ...   ...   ...\n",
       "76  20210497  郑幸亩   1992/11/1  16042478935   2021/10/5  1748  2661\n",
       "77  20210498  陶宦赛   1995/9/28  16549247662   2021/4/22  4648  1484\n",
       "78  20210499  郑苇丸   1997/9/25  16197269012   2021/5/23  1694  2547\n",
       "79  20210500   邹姻    1997/9/6  15561529882    2021/4/8  1320  1030\n",
       "80  20210501   周花   2000/1/11  12345678901    2022/7/6     0  4014\n",
       "\n",
       "[81 rows x 7 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 查看某位会员消费记录\n",
    "\n",
    "def read_someone_cast():\n",
    "    users = read_user_csv()\n",
    "    display(users)\n",
    "    user_names = users['姓名'].values.tolist()\n",
    "    casts = read_cast_csv()\n",
    "    \n",
    "    while True:\n",
    "        user_name = input(\"请输入会员姓名：\")\n",
    "        if user_name not in user_names:\n",
    "            print_message(\"会员不存在，请重新输入！\")\n",
    "            continue\n",
    "        else:\n",
    "            user = users.loc[(users['姓名'] == user_name),:]\n",
    "            user_id  = list(user.to_dict()[\"会员ID\"])[0]\n",
    "            user_cast = casts.loc[(casts['会员ID'] == user_id),:]\n",
    "            print_message(\"会员【{}】消费记录查找成功！\".format(user_name))\n",
    "            display(user_cast)\n",
    "            break\n",
    "            \n",
    "read_someone_cast()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 案例练习："
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "根据上述内容，现有一名新顾客小兰（女，26岁，tel:111112222，等信息）要注册会员并进行充值，请添加此会员信息并充值一万元。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
